<?php
if (!defined('FosfoaSystem')) {
    exit(1);
}
import($GLOBALS['spConfig']['controller_path'] . '/general.php');
class qx extends general
{
    public $arrqx;
    public function __construct()
    {
        parent::__construct();
        $this->tpl_title = T("Dashboard");
        $this->navigation_current = 'qx';
        $this->arrqx = spClass('spAclModel')->findAll(null, 'sort asc,aclid asc');
    }
    function index()
    {
        $tree = spClass('Tree');
        $tree->treelist($this->arrqx);
        //$nav=$tree->navi(3);
        $arr = $tree->leaf(0);
        //print_r($nav);
        //print_r($arr);
        $this->arr = $arr;
        //$this->nav = $nav;
        //$this->tqx = $arrqx;
        $this->display("admin/qx_index.html");
    }
    function add()
    {
        $this->menuview = array(
            0 => '头部',
            1 => '左部',
            2 => '不显');
        $aclid = $this->spArgs("aclid", 0);
        $tree = spClass('Tree');
        $tree->treelist($this->arrqx);
        $arr = $tree->leaf(0);
        $this->arr = $arr;
        $this->aclid = $aclid;
        $this->addtitle = "添加新权限";
        $this->display("admin/qx_add.html");
    }
    function edit()
    {
        $this->menuview = array(
            0 => '头部',
            1 => '左部',
            2 => '不显');
        $id = $this->spArgs("aclid", 0);
        $Objacl = spClass('spAclModel');
        $acl = $Objacl->findacl($id);
        $this->acl = $acl;
        $aclid = $acl["fid"];
        $tree = spClass('Tree');
        $tree->treelist($this->arrqx);
        $arr = $tree->leaf(0);
        $this->arr = $arr;
        $this->aclid = $aclid;
        $this->addtitle = "修改权限";
        $this->display("admin/qx_add.html");
    }
    function order()
    {
        $selids = $this->spArgs("selids");
        $orderid = $this->spArgs("orderid");
        $Obj = spClass('spAclModel');
        $selarray = explode(',', $selids);

        foreach ($selarray as $aclid) {
            $condition = array('aclid' => $aclid);
            $dataform = array('sort' => $orderid[$aclid]);
            $Obj->update($condition, $dataform);
        }
        $this->success(T('Successfully Order!'), spUrl("qx", "index"));
    }
    function del()
    {
        $Obj = spClass('spAclModel');
        $aclid2 = $this->spArgs("aclid", 0);
        if ($aclid2 == 0) {
            $selids = $this->spArgs("selids");
            $selarray = explode(',', $selids);

            foreach ($selarray as $aclid) {
                $conditions = array('aclid' => $aclid);
                $Obj->delete($conditions); // 删除记录
            }
        } else {
            $conditions = array('aclid' => $aclid2);
            $Obj->delete($conditions); // 删除记录
        }
        $msg = "删除权限" . $aclid2;
        Savelog($msg);
        $this->success(T('Successfully  deleted!'), spUrl("qx", "index"));
    }
    function saveqx()
    {
        $type = $this->spArgs("aclid", 0);
        $dataform = array(
            'name' => urldecode($this->spArgs("name")),
            'fid' => $this->spArgs("fid"),
            'controller' => $this->spArgs("controller"),
            'action' => $this->spArgs("action"),
            'menuview' => $this->spArgs("menuview"),
            'sort' => $this->spArgs("sort"),
            );
        $Obj = spClass('spAclModel');
        if ($type == 0) {
            $Obj->create($dataform);
            $msg = "新权限" . $dataform[name] . "添加成功";
        } else {
            $condition = array('aclid' => $this->spArgs("aclid"));
            $Obj->update($condition, $dataform);
            $msg = "权限" . $dataform[name] . "修改成功";

        }
        Savelog($msg);
        $result = array(
            'status' => 1, // 标志
            'message' => $msg, // 提示信息
            );
        echo json_encode($result); // 返回（显示）JSON结果
    }
}